package org.small.shop.phone.api.process.goods.controller;

import java.util.List;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.small.shop.phone.api.process.goods.pojo.TblWxGoods;
import org.small.shop.phone.api.process.goods.pojo.WxShowGoodsVo;
import org.small.shop.phone.api.process.goods.service.TblWxGoodsService;
import org.small.shop.phone.api.process.orders.controller.TblWxOrdersController;
import org.small.shop.phone.api.utils.ShopJSONResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TblWxGoodsController {

	private static Logger logger = LoggerFactory.getLogger(TblWxOrdersController.class);

	@Resource
	private TblWxGoodsService goodsService;

	@PostMapping("/selectShowGoodsByType")
	public ShopJSONResult selectShowGoodsByType(WxShowGoodsVo goodsVo) throws Exception {

		try {
			List<WxShowGoodsVo> goodsList = goodsService.getGoodsListByType(goodsVo);
			if (goodsList != null && !goodsList.isEmpty()) {
				goodsVo.setList(goodsList);
				return ShopJSONResult.ok(goodsVo);
			}
		} catch (Exception e) {
			logger.info(e.getMessage());
		}

		return ShopJSONResult.errorMsg("查询商品失败！");
	}

	@PostMapping("/selectPopularSelling")
	public ShopJSONResult selectPopularSelling() {

		try {
			List<WxShowGoodsVo> goodsList = goodsService.getGoodsListPopularSelling();
			if (goodsList != null && !goodsList.isEmpty()) {
				return ShopJSONResult.ok(goodsList);
			}
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return ShopJSONResult.errorMsg("查询商品失败！");
	}

	@PostMapping("/login/getGoodsById")
	public ShopJSONResult getGoodsById(Integer goodsId) {

		if (goodsId != null) {
			try {

				TblWxGoods goods = goodsService.selectGoodsByGoodsId(goodsId);
				if (goods != null) {
					return ShopJSONResult.ok(goods);
				}
			} catch (Exception e) {
				logger.info(e.getMessage());
			}
		}
		return ShopJSONResult.errorMsg("查询商品失败！");
	}

}
